package com.ycp.erp.warehouse.ui.binder;

import android.graphics.Color;
import android.text.SpannableString;
import android.text.Spanned;
import android.text.style.ForegroundColorSpan;
import android.view.View;
import android.widget.EditText;
import android.widget.TextView;

import com.one.common.view.multitytype.adapter.BaseItemBinder;
import com.one.common.view.multitytype.adapter.BaseViewHolderMulti;
import com.ycp.erp.R;
import com.ycp.erp.warehouse.model.bean.Warehouse;

import androidx.annotation.NonNull;

/**
 * Class Des:
 * Created by bjh on 2021/8/24.
 */
public class OutWarehouseSelectBinder extends BaseItemBinder<Warehouse> {
    public OutWarehouseSelectBinder() {
        super(R.layout.item_out_warehouse_select);
    }

    @Override
    protected void bindView(@NonNull BaseViewHolderMulti holder, Warehouse item) {
        View ivAdd = holder.getView(R.id.ivAdd);
        View ivReduce = holder.getView(R.id.ivReduce);
        TextView tvWarehouseName = holder.getView(R.id.tvWarehouseName);
        EditText etNum = holder.getView(R.id.etGoodsNum);
        TextView tvGoodsPrice = holder.getView(R.id.etGoodsPrice);
        tvGoodsPrice.setText(item.getGoodsPrice());
        etNum.setText(String.format("%s", item.getOutGoodsNum()));
        SpannableString spannableString = new SpannableString("库房："+item.getWarehouseName());
        ForegroundColorSpan colorSpan = new ForegroundColorSpan(Color.parseColor("#E79659"));
        spannableString.setSpan(colorSpan, 3, spannableString.length(), Spanned.SPAN_INCLUSIVE_EXCLUSIVE);
        tvWarehouseName.setText(spannableString);
        ivAdd.setOnClickListener(v -> {
            if (item.getGoodsTotalNum()>item.getOutGoodsNum()){
                item.setOutGoodsNum(item.getOutGoodsNum() + 1);
                etNum.setText(String.format("%s", item.getOutGoodsNum()));
            }
        });
        ivReduce.setOnClickListener(v -> {
            if (item.getOutGoodsNum() > 0) {
                item.setOutGoodsNum(item.getOutGoodsNum() - 1);
                etNum.setText(String.format("%s", item.getOutGoodsNum()));
            }
        });
    }
}
